import ddt
import os
import unittest
from page.login_page import LoginPage
from page.index_page import IndexPage
from page.receiving_address_page import ReceivingAddressPage
from common.functions import browser_operation
from common.data_operation import DataOperation

# TODO 文件路径
project_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
path = os.path.join(project_path,'data/address.xls')
addr_list = DataOperation(path).get_data_to_dict()

@ddt.ddt()
class ReceivingAddressTastCase(unittest.TestCase):

    @classmethod
    def setUpClass(cls) -> None:
        # TODO 打开浏览器，登录账户
        driver = browser_operation()
        cls.receiving_addr = ReceivingAddressPage(driver)
        cls.index = IndexPage(driver)
        cls.login = LoginPage(driver)
        cls.login.get_website('http://172.16.140.55/ecshop/user.php')
        cls.login.input_username('豆芽纸')
        cls.login.input_password('123456')
        cls.login.btn_login()


    @ddt.data(*addr_list)
    def test_receiving_address(self,data):
        # TODO 点击：收货地址 按钮
        self.receiving_addr.btn_receiving_address()

        # TODO 定位选择省份，添加：province
        self.receiving_addr.select_province(data['province'])

        # TODO 定位选择市，添加：city
        self.receiving_addr.select_city(data['city'])

        # TODO 定位选择区，添加：area
        self.receiving_addr.select_district(data['area'])

        # TODO 定位收货人姓名，添加：consignee_name
        self.receiving_addr.consignee_name(data['consignee_name'])

        # TODO 定位详细地址，添加：detailed_address
        self.receiving_addr.detailed_addr(data['detailed_address'])

        # TODO 定位电话，添加：telephone
        self.receiving_addr.telephone(data['telephone'])

        # TODO 定位电子邮件地址，添加：e-mail_address
        self.receiving_addr.email_addr(data['e-mail_address'])

        # TODO 定位邮政编码，添加：postal_code
        self.receiving_addr.postal_code(data['postal_code'])

        # TODO 定位手机，添加：mobile_phone
        self.receiving_addr.mobile_phone(data['mobile_phone'])

        # TODO 定位新增收货地址按钮，添加：
        self.receiving_addr.add_receiving_address()

        # TODO 断言  确认：是否存在：确认修改按钮 定位：class="bnt_blue"
        comf = self.receiving_addr.get_comfirm()
        self.assertEqual('确认修改',comf)

    # def tearDown(self) -> None:
    #     # TODO 退出登录
    #     self.index.logout()
    
    @classmethod
    def tearDownClass(cls) -> None:
        # TODO 关闭浏览器
        cls.receiving_addr.quit()

if __name__ == '__main__':
    unittest.main(verbosity=2)